package rsb21424yhc.d1125;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

public class Demo01 {
    public static void main(String[] args) {
        List <Integer> list =new ArrayList<>();
        Collections.addAll(list,25,60,94,80,75,12,35,65,46);//
        double x=  list.stream().mapToInt(a->a).average().getAsDouble();//stream流求平均数
        System.out.println(x);
        System.out.println("排序前"+list);
        Collections.sort(list);//排序
        System.out.println(list);
        Collections.sort(list,(o1,o2)->o1-o2);//简写
        System.out.println(list);
        //forEach方法
        list.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                if (integer==75){
                    integer=100;//无法修改成功
                    //intteger.setXX=100;成功
                }
                System.out.print(integer+"   ");
            }//集合的遍历 无返回值 内部输出
        });
        //list.forEach((integer -> System.out.println(integer)));//简写的foreach

        /*Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });*/
    }
}
